package tester;

import java.util.Iterator;
import java.util.Random;

import java.lang.Math;

import oop.ex1.dataStructures.*;
import oop.ex1.processToolKit.*;
import oop.ex1.processToolKit.Process;

public class tester {
	
	private LIFOComparableQueue lcq;
	
	public static void main(String args[]) {
		
		System.out.println("You must set the default size to 5");
		
		System.out.println("Testing LIFOComparableQueue");
		System.out.println("===========================");
		///////////////////////////////////////////////////////
		////////////Test the LIFOComparableQueue///////////////
		///////////////////////////////////////////////////////
		LIFOComparableQueue lcq = new LIFOComparableQueue();
		/*
		 * Create Dummy processes
		 */
		Process p1 = new Process("p1",null,7);
		Process p2 = new Process("p2",null,2);
		Process p3 = new Process("p3",null,16);
		Process p4 = new Process("p4",null,3);
		Process p5 = new Process("p5",null,10);
		Process p6 = new Process("p6",null,4);
		Process p7 = new Process("p7",null,14);
		Process p8 = new Process("p8",null,8);
		Process p9 = new Process("p9",null,1);
		Process p10 = new Process("p10",null,9);
		Process p11 = new Process("p11",null,9);
		
		/*
		 * Test an empty queue 
		 */
		System.out.println("|| Test an empty queue ||");
		
		System.out.println("Testing the peek method..");
		try {
			lcq.peek();
		} catch (EmptyQueueException e) {
			System.out.println(e.toString());
		}
		System.out.println("Testing the poll method..");
		try {
			lcq.poll();
		} catch (EmptyQueueException e) {
			System.out.println(e.toString());
		}
		
		
		/*
		 * Test a null insertion
		 */
		System.out.println("|| Test a null insertion ||");
		
		lcq.push(null);
		System.out.println("Testing the peek method..");
		try {
			lcq.peek();
		} catch (EmptyQueueException e) {
			System.out.println(e.toString());
		}
		System.out.println("Testing the poll method..");
		try {
			lcq.poll();
		} catch (EmptyQueueException e) {
			System.out.println(e.toString());
		}
		
		/*
		 * 
		 */
		System.out.println("|| Test an insertion ||");
		
		System.out.println("Pushing 11 elements");
		lcq.push(p1);
		lcq.push(p2);
		lcq.push(p3);
		lcq.push(p4);
		lcq.push(p5);
		lcq.push(p6);
		lcq.push(p7);
		lcq.push(p8);
		lcq.push(p9);
		lcq.push(p10);
		lcq.push(p11);
		System.out.println("Polling all processes plus one not using the iterator..");
		for(int i=0;i<12;i++) {
			try {
				lcq.poll();
			} catch (EmptyQueueException e) {
				System.out.println(e.toString());
			}
		}
		lcq.push(p1);
		lcq.push(p2);
		lcq.push(p3);
		lcq.push(p4);
		lcq.push(p5);
		lcq.push(p6);
		lcq.push(p7);
		lcq.push(p8);
		lcq.push(p9);
		lcq.push(p10);
		lcq.push(p11);
		System.out.println("Iterateing all processes using the LIFOIterator..");
		for(Iterator it1 = lcq.LIFOIterator();it1.hasNext();) {
			System.out.println(((Process)(it1.next())).toString());
		}
		System.out.println("Iterateing all processes using the RandomIterator..");
		for(Iterator it1 = lcq.RandomIterator(1234);it1.hasNext();) {
			System.out.println(((Process)(it1.next())).toString());
		}
	
	
	
	System.out.println("Testing PriorityQueue");
	System.out.println("===========================");
	///////////////////////////////////////////////////////
	//////////////////Test the Priority Queue//////////////
	///////////////////////////////////////////////////////
	
	
	
	
	
	
	System.out.println("Testing ProcessManager");
	System.out.println("===========================");
	///////////////////////////////////////////////////////
	/////////////////Test the Process Manager//////////////
	///////////////////////////////////////////////////////
	
	ProcessManager pm = new ProcessManager();
	/*
	 * Create Dummy processes
	 */
	Process pm1 = new Process("pm1",null,7);
	Process pm2 = new Process("pm2",pm1,2);
	Process pm3 = new Process("pm3",pm1,16);
	Process pm4 = new Process("pm4",pm2,3);
	Process pm5 = new Process("pm5",pm2,10);
	Process pm6 = new Process("pm6",pm2,4);
	Process pm7 = new Process("pm7",pm2,14);
	Process pm8 = new Process("pm8",pm3,8);
	Process pm9 = new Process("pm9",pm4,10);
	Process pm10 = new Process("pm10",pm4,30);
	Process pm11 = new Process("pm11",null,9);
	
	pm.addProcessTree(pm1);
	
/*	try {
		pm.updatePriority(pm1, 200);
	} catch (ObjectNotFoundException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}*/
	
	try {
		pm.updatePriority(pm5, 1);
		pm.updatePriority(pm3, 30);
		pm.updatePriority(pm2, 100);
		pm.updatePriority(pm6, 70);
		pm.updatePriority(pm8, 5);
		pm.updatePriority(pm1, 4);
		
	} catch (ObjectNotFoundException e1) {
		// TODO Auto-generated catch block
		System.out.println(e1);
	}
	
	try {
		pm.runAllProcesses();
	} catch (DisorderException e) {
		// TODO Auto-generated catch block
		System.out.println(e);
	}
	
	
	
	
	
	}
}
